package com.zenika.zenbinding.client.converter;

import com.zenika.zenbinding.client.exception.ConverterException;

/**
 * Converter for the Byte class.
 * @author Zenika
 */
public class ByteConverter implements Converter {

	public String fromObjectToString(Object object) throws ConverterException {
		try {
			Byte value = (Byte) object;
			return value.toString();
		} catch (ClassCastException e) {
			throw new ConverterException("The object is not a byte");
		}
	}

	public Object fromStringToObject(String string) throws ConverterException {
		try {
			Byte result = new Byte(string);
			return result;
		} catch (NumberFormatException e) {
			throw new ConverterException("Error during the convertion");
		}
	}

}
